<?php
namespace app\Admin\controller\post;

//引入公共控制器
use app\common\controller\Backend;


class Cate extends Backend
{
     
    
   
    
    public function __construct(){

        //继承父类
        parent::__construct();

        $this->PostModel = model('Post.Post');
    
    }   
    
    // 配置列表页
    public function index()
    {
        $count = $this->PostModel->count();

        $countlist = $this->PostModel->paginate(10);

        // $countlist = $this->PostModel->alias('c')->join('cate p','p.id=c.cateid')->paginate(10);

        // echo $this->PostModel->getLastSql();
        // exit;

        // var_dump($countlist);
        // exit;

        $pagestr = $countlist->render();

    

        $this->assign([
            'count' => $count,
            'countlist' => $countlist,
            'pagestr' => $pagestr
        ]);

        return $this->fetch();
    }

    public function del()
    {
        if($this->request->isPost()){

            $success = [
                'result' => false,
                'msg' => ''
            ];

            $ids = $this->request->param('ids', 0);

            $result = $this->PostModel->destroy($ids);


            if($result === FALSE)
            {
                $success['result'] = false;
                $success['msg'] = $this->PostModel->getError();
            }else
            {
                $success['result'] = true;
                $success['msg'] = '删除配置成功';
            }

            return json($success);
        }
    }
    

}